#include <stdlib.h>
#include <string.h>

#include "ExtremeC_examples_chapter8_2_person.h"
#include "ExtermeC_examples_chapter8_2_person_p.h"

//前向声明
typedef struct {
    //这里继承 person 类的所有属性，并且由于采用嵌套，还可以使用它的所有行为函数
    person_t person;
    char* student_number;
    unsigned int passed_credits; 
} student_t;

//内存分配函数
student_t* student_new()
{
    return (student_t* )malloc(sizeof(student_t));
}

//构造函数
void student_ctor(student_t* student, const char* first_name, const char* last_name, 
                  unsigned int birth_year, const char* student_number, unsigned int passed_credits)
{
    //调用父类的构造函数
    person_ctor((struct person_t*)student, first_name, last_name, birth_year);
    student->student_number = (char*)malloc(16 * sizeof(char));
    strcpy(student->student_number, student_number);
    student->passed_credits = passed_credits;
}

//析构函数
void student_dtor(student_t* student)
{
    //首先需要销毁子对象
    free(student->student_number);
    //然后调用父类的析构函数
    person_dtor((struct person_t* )student);
}

//行为函数
void student_get_student_number(student_t* student, char* buffer)
{
    strcpy(buffer, student->student_number);
}

unsigned int student_get_passed_credits(student_t* student)
{
    return student->passed_credits;
}